<template>
	<view class="content">
		<view class="top">
			<customHeader>
                <template v-slot:title>旭春灯饰生产信息管理生产看板</template>
            </customHeader>
		</view>
		<view class="center">
			<view style="border: 2rpx solid #ed1c24; margin-top: 20rpx; padding: 20rpx;">
				<view class="search_content">
					<view class="item_search" style="width: 30%;" >
						<text class="title">组别信息:</text>
						<mySelectCheckbox 
							v-model="form.zbinfo" 
							style="flex: 1; width: 400rpx; height: 50rpx;"
							dataKey="name" 
							dataValue="id" 
							:localdata="zbinfoSelectList"  
							@change="changeZbinfo"></mySelectCheckbox>
							<button class="refreshBtn" hover-class="hover_refresh" @click="_getInforList" >刷新</button>
					</view>

					<!-- <view class="item_search" style="width: 40%;" >
						<text class="title">组长:</text>
						<input 
							class="input"
							v-model="form.teamLeader"
							disabled
						/>
					</view> -->

					<view class="item_search" style="width: 25%;">
						<text class="title">组员:</text>
						<input 
							class="input"
							v-model="form.members"
							disabled
						/>
					</view>
					<view class="item_search" style="width: 25%;">
						<text class="title">完成状态:</text>
						<customDownSearch
							style="flex: 1; height: 30rpx; border: 1rpx solid #ccc; font-size: 30rpx;"
							:options="compStateList"
							:value="mainTable"
							v-model="mainTable"
							@changeInput="changeMainTable"
							@input="inputMainTable"
						></customDownSearch>
					</view>
					<!-- <button @click="handleSearch" hover-class="btn" style="margin: 0; width: 320rpx; background: #008fe0; color: #fff; ">查询</button> -->
				</view>

				<view class="search_content" style="margin-top: 30rpx;" >
					<view class="item_search" style="margin-right: 12rpx;">
						<text class="title" style="margin-right: 12rpx;">当前订单数:</text>
						<input 
							class="input"
							text="number"
							v-model="form.dqdds"
							disabled
						/>
					</view>

					<view class="item_search" style="margin-right: 12rpx;">
						<text class="title" style="margin-right: 12rpx;">当前订单数量:</text>
						<input 
							class="input"
							text="number"
							v-model="form.dqddNum"
							disabled
						/>
					</view>
					<view class="item_search" style="margin-right: 12rpx;">
						<text class="title" style="margin-right: 12rpx;">当日完成数量:</text>
						<input 
							class="input"
							text="number"
							v-model="form.drwcNum"
							disabled
						/>
					</view>
					<view class="item_search" style="margin-right: 12rpx;">
						<text class="title" style="margin-right: 12rpx;">未完成数量:</text>
						<input 
							class="input"
							text="number"
							v-model="form.noNum"
							disabled
						/>
					</view>
					<view class="item_search" >
						<text class="title" style="margin-right: 12rpx;">本组累计产量:</text>
						<input 
							class="input"
							text="number"
							v-model="form.bzljcl"
							disabled
						/>
					</view>
				</view>
			</view>

			<view style="border: 2rpx solid #ffbf93; padding: 20rpx; flex: 1; ">
				
				<scroll-view :scroll-top="0" scroll-y="true" class="table_content" @scrolltolower="handleScroll1">
					<t-table >
						<t-tr style="position: sticky; top: 0; width: 100%; background: #fff; " >
							<t-th style="flex:0 0 80upx;word-break: break-all;">序号</t-th>
							<t-th>订单编号</t-th>
							<t-th style="flex:0 0 220upx;">订单备注</t-th>
							<t-th>订单数量</t-th>
							<t-th>生产状态</t-th>
							<t-th>完成状态</t-th>
							<t-th>件数</t-th>
						</t-tr>
						<view  v-for="(item, index) in data1" :key="item.id" @click="handleItem(item, index)">
							<t-tr :style="{ backgroundColor: item.active ? '#81d3f8' : '' }">
								<t-td style="flex:0 0 80upx;word-break: break-all;">{{ index+1 }}</t-td>
								<t-td>{{ item.no }}</t-td>
								<t-td  style="flex:0 0 220upx;">{{ item.remark }}</t-td>
								<t-td>{{ item.total }}</t-td>
								<t-td>{{ normalMap[item.normal] }}</t-td>
								<t-td>{{ completedMap[item.completed] }}</t-td>
								<t-td>{{ item.pieces }}</t-td>
							</t-tr>
						</view>
					</t-table>
				</scroll-view>
			</view>

			<!--  -->

			<view style="border: 2rpx solid #9fa3e5; padding: 20rpx; margin-bottom: 20rpx;">

				<view class="center_1">
					<view class="center_item">
						<view class="item_title">订单详情: </view>
						<view>{{ ddNo }}</view>
					</view>
					<view class="center_item" style="margin-left: 60rpx;">
						<view class="item_title">订单数量: </view>
						<view>{{ddNum}}</view>
					</view>

					<view class="bao_btn">
						<button @click="handleEdit" hover-class="btn_hover"> {{ showEdit ? '完成' : '修改' }} </button>
						<button style="margin-left: 20rpx;" hover-class="btn_hover" @click=handlePrintPopupBox>打印</button>
					</view>
					<view class="center_item" style="width: 25%;">
						<text class="item_title">完成状态:</text>
						<customDownSearch
							style="flex: 1; height: 30rpx; border: 1rpx solid #ccc; font-size: 30rpx;"
							:options="compSubStateList"
							:value="subTable"
							v-model="subTable"
							@changeInput="changeSubTable"
							@input="inputSubTable"
						></customDownSearch>
					</view>

				</view>

				<view style="width: 100%; overflow: auto;" >
					<view  class="table_2_content">
						<t-table>
							<t-tr style="position: sticky; top: 0; width: 100%; background: #fff; z-index: 1; ">
								<t-th style="flex:0 0 90upx;">/</t-th>
								<t-th style="flex:0 0 220upx;">货号</t-th>
								<t-th >名称</t-th>
								<t-th style="flex:0 0 140upx;word-break: break-all;">辅助数量</t-th>
								<!-- <t-th style="flex:0 0 60upx;word-break: break-all;">件数 3## </t-th> -->
								<t-th style="flex:0 0 120upx;word-break: break-all;">订单数量</t-th>
								<t-th style="flex:0 0 120upx;word-break: break-all;">生产数量</t-th>
								<t-th style="flex:0 0 120upx;word-break: break-all;">配货数量</t-th>
								<t-th style="flex:0 0 120upx;">完成数量</t-th>
								<t-th style="flex:0 0 120upx;word-break: break-all;">员工</t-th>
								<t-th style="flex:0 0 220upx;">订单备注</t-th>
								<t-th style="flex:0 0 220upx;">生产备注</t-th>
								<t-th style="flex:0 0 120upx;word-break: break-all;">完成状态</t-th>
							</t-tr>
							<view  v-for="(item, index) in data2" :key="index">
								<t-tr>
									<t-td style="flex:0 0 90upx;">
										<checkbox-group @click="changeMxBox(item)">
											<label class="uni-list-cell uni-list-cell-pd">
												<view>
													<checkbox :checked="item.mxCheck" />
												</view>
											</label>
										</checkbox-group>
									</t-td>
									<t-td style="flex:0 0 220upx;" :style="{ background: item.completed ? '#89d961' : '#fff' }" >
										<view class="bao_td_left" >
											{{ item.materiel_no }}
										</view>
									</t-td>
									<t-td :style="{ background: item.free == 'true' ? '#f9b344' : '#fff' }" >
										<view class="bao_td_left" @click="handleBomPopup(item.materiel_id)" style="position: relative;" >
											<textarea 
												style="width: 100%; text-align: left; font-weight: 500; font-size: 26rpx;" 
												:auto-height="true"
												disabled
												v-model="item.materiel_name" />
											<view style="position: absolute; right: 0; top: 0; left: 0; bottom: 0;"></view>
										</view>
									</t-td>
									<t-th style="flex:0 0 140upx;word-break: break-all;">
										<!-- <input type="number" v-model.number="item.materiel_rate2" /> -->
										{{ getFzSl(item.yquantity, item.materiel_rate2) }}
									</t-th>
									<!-- <t-td style="flex:0 0 60upx;word-break: break-all;">{{ item.pieces }} 3##</t-td> -->
									<t-td style="flex:0 0 120upx;word-break: break-all;">{{ item.yquantity }}</t-td>
									<t-td style="flex:0 0 120upx;word-break: break-all;">{{ (item.yquantity - item.phquantity).toFixed(0) }}</t-td>
									<t-td style="flex:0 0 120upx;word-break: break-all;">
										
										<view style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;" :style="{ 
											'color': item.color == 'blue' ? '#18aff2' : 
													item.color == 'green' ? '#63a103' : 'red' }" 
											@click="handlePhsl(item)" >
													{{ item.phquantity || 0 }} 
										</view>
									</t-td>
									<t-td style="flex:0 0 120upx;">
										<view style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;"@click="handleNumRecords(item)">
											{{ item.quantity }}
										</view>
									</t-td>
									<t-td style="flex:0 0 120upx;word-break: break-all;">
										<view style="width: 100%; height: 100%; " @click="handleEmployee(item, index)">
											{{ item.staffsStr }}
										</view>
									</t-td>
									<t-td  style="flex:0 0 220upx;">{{ item.sorderi_remark }}</t-td>
									<t-td  style="flex:0 0 220upx;">
										<textarea 
											:maxlength="-1" 
											style="max-height: 80rpx; width: 100%;" 
											v-model="item.remark" 
											:disabled="!showEdit"
										/>
									</t-td>
									<t-td style="flex:0 0 120upx;word-break: break-all;background: #63a103;" 
										:style="{'background': item.completed ? '#63a103' : '', 'color': item.completed ? '#fff' : '' }" 
										>
										<view  @click="handleStatus(item, index)">
											{{ completedMap[item.completed]}}
										</view>
									</t-td>
								</t-tr>
							</view>
						</t-table>
					</view>
				</view>
				

			</view>
		</view>

		<!--  -->

        <u-popup round="35" :show="showPopup" @close="showPopup = false" @open="handleOpen" mode="center">
            <view class="popup_content">
				<!--  -->
				<view  v-if="popuptitle == '员工信息'">
					<view  class="title">{{ popuptitle }}</view>
					<view class="popup_search">
						<input v-model="employeeName" />
						<button @click="queryName" hover-class="btn">查询</button>
					</view>
					<view class="selectAll_content">
						<checkbox-group @change="changeAll">
							<label>
								<checkbox value="selectAll" :checked="selectAll" /> 全选
							</label>
						</checkbox-group>

						<button @click="handleSearchGroupEmployees" hover-class="btn">本组员工</button>
					</view>
					<view class="checked_content">
						<scroll-view :scroll-top="0" scroll-y="true" class="table_3_content">
							<checkbox-group @change="checkboxChange">
								<label class="label_item" v-for="(item, index) in employeeList" :key="item.id">
									<view>
										<checkbox :value="item.no" :checked="item.checked" />
									</view>
									<view>{{ item.no }} - {{ item.name }} </view>
								</label>
							</checkbox-group>
						</scroll-view>
					</view>

					<view class="popup_btn">
						<button  hover-class="btn" @click="confirmEmployee">确定</button>
						<button hover-class="btn1" @click="handleCancel">取消</button>
					</view>
				</view>
				<!--  -->
                <view v-else>
					<view  class="title">{{ popuptitle }}</view>
					<view class="checked_content">
						<scroll-view :scroll-top="0" scroll-y="true" class="table_3_content">
							<radio-group @change="radioChange">
								<label class="label_item" v-for="(item, index) in statusList" :key="index">
									<view>
										<radio  :value="item.labed" :checked="item.checked" />
									</view>
									<view style="font-size: 40rpx;">{{ item.labed }}</view>
								</label>
							</radio-group>
						</scroll-view>
					</view>
					<view class="popup_btn">
						<button hover-class="btn" @click="confirmStatus">确定</button>
						<button hover-class="btn1" @click="showPopup = false">取消</button>
					</view>
				</view>
				<!--  -->
				<view v-if="showToast" class="toast" >
					<view class="toast_msg" v-html="showToastStr"></view>
				</view>
            </view>
			<!--  -->
		</u-popup>

		<!-- 商品名称 BOM明细 -->
		<u-popup round="15" :show="showBomPopup" @close="showBomPopup = false" mode="center" :closeable="true">
			<view class="Bom_popup_comtent" >
				<view class="title">
					BOM明细
				</view>
				<view style="overflow: auto; flex: 1;">
					<view style="min-width: 1800rpx;">
						<t-table>
							<t-tr>
								<t-th style="flex:0 0 71upx;">序号</t-th>
								<t-th style="flex:0 0 250upx;word-break: break-all;">物料编号</t-th>
								<t-th >物料名称</t-th>
								<t-th style="flex:0 0 200upx;word-break: break-all;">单位</t-th>
								<t-th style="flex:0 0 220upx;">数量</t-th>
							</t-tr>
							<t-tr v-for="(item,index) in domList" :key="index">
								<t-th style="flex:0 0 71upx;">{{ index+1 }}</t-th>
								<t-th style="flex:0 0 250upx;word-break: break-all;">{{ item.materiel_no }}</t-th>
								<t-th >
									<view style="width: 100%; height: 100%;">
										<textarea 
											style="width: 100%; text-align: left; font-weight: 500;" 
											:auto-height="true"
											disabled
											v-model="item.materiel_name" />
									</view>
								</t-th>
								<t-th style="flex:0 0 200upx;word-break: break-all;">{{ item.materiel_unit_text }}</t-th>
								<t-th style="flex:0 0 220upx;">{{ item.quantity }}</t-th>
							</t-tr>
						</t-table>
					</view>
				</view>
				<!-- <view>底部啊</view> -->
			</view>
		</u-popup>

		<!-- 完成数量 弹出框 -->
		<uni-popup round="15" ref="complNumPopup" type="center">
			<view class="Bom_popup_comtent" style="width: 1200rpx; max-height: 50vh; font-size: 39rpx;">
				<view class="title">
					完成数量
				</view>

				<view style="overflow: auto; flex: 1;">
					<view>
						<view style="display: flex; align-items: center; border-bottom: 1rpx solid #d1d1d1;">
							<view>完工数量:</view>
							<input style="flex: 1; font-size: 40rpx; margin-left: 50rpx;" v-model.number="numPupopMap.differenceNum" />
						</view>
						<view style="display: flex; align-items: center; border-bottom: 1rpx solid #d1d1d1;">
							<view>员工:</view>
							<button size="mini" style="width: 170rpx;" hover-class="hover_btn" @click="handleEmploy1" >请选择</button>
							<!-- <input disabled style="flex: 1; font-size: 40rpx; margin-left: 5rpx;" v-model="numPupopMap.employNameStr" placeholder="多选" /> -->
							<view style="flex: 1; font-size: 40rpx; margin-left: 5rpx;">
								{{  numPupopMap.employNameStr? numPupopMap.employNameStr : '多选'  }}
							</view>
						</view>
						<view style="display: flex; align-items: center; border-bottom: 1rpx solid #d1d1d1; padding-top: 20rpx;" v-for="(item, index) in numPupopMap.reportDtl" :key="index">
							<view>完工数量：{{ item.quantity }} ,</view>
							<view style="margin-left: 25rpx;">完工时间：{{ item.endtime }}</view>
							<view style="margin-left: 25rpx;">
								<view v-for="(item1, index1) in item.staffs" :key="index1"> {{ item1.name }}; </view>
							</view>

						</view>
					</view>
				</view>
				<view class="bom_bottom">
					<button hover-class="hover_btn" @click="handleNumPopup">确认</button>
					<button hover-class="hover_btn" @click="handleCancelNum">取消</button>
				</view>
			</view>
		</uni-popup>

		<!-- 完成数量 选择员工 -->
		<uni-popup ref="employPopup" type="center">
			<view class="employee_popup">
				<view class="title" >
					<view>请选择员工</view>
					<button @click="clearEmploy" hover-class="hover_btn" >清空</button>
				</view>
				<view class="employee_list">
					<view v-if="staffsList.length" v-for="(item, index) in staffsList" :key="index" >
						<checkbox-group @click="selectEmploy(item)">
							<label class="label_item">
								<view>
									<checkbox :value="item.no" :checked="item.checked" />
								</view>
								<view>{{ item.no }} - {{ item.name }} </view>
							</label>
						</checkbox-group>
					</view>
					<view v-if="!staffsList.length" > 暂无数据!!! </view>
				</view>
				
				<view class="footer" >
					<button hover-class="hover_btn" @click="selectEmploySure" >确认</button>
					<button hover-class="hover_btn" @click="selectEmployClose" >取消</button>
				</view>
			</view>
		</uni-popup>
		<!-- 完成数量 选择员工 -->


		<!-- 打印修改 数量 弹出框 开始 -->
		<uni-popup ref="printPopup" type="center">
			<view class="print_popup">
				<view style="font-size: 45rpx; margin: 10rpx 0; border-bottom: 1rpx solid #d1d1d1; ">打印份数</view>
				<view style="flex: 1; overflow: auto; ">
					<!-- <view class="dis_flex">
						<view>份数:</view>
						<input type="number" v-model.number="printSl" placeholder="请输入打印份数"/>
					</view> -->
					<t-table style="width: 100%;">
						<t-tr style="position: sticky; top: 0; width: 100%; background: #fff; z-index: 9; " >
							<t-th>货号</t-th>
							<t-th>份数</t-th>
							<t-th>装箱数</t-th>
						</t-tr>

						<t-tr v-for="(item, index) in (printList || [])" :key="index">
							<t-th>{{item.materiel_name || ''}}</t-th>
							<t-th>
								<input type="number" v-model="item.printSl" placeholder="请输入打印份数" />
							</t-th>
							<t-th>
								<input type="number" v-model="item.materiel_rate2" placeholder="请输入装箱数" />
							</t-th>
						</t-tr>
					</t-table>

				</view>
				<view class="dis_flex" style=" justify-content: space-around; padding: 10rpx 0; border-top: 1rpx solid #d1d1d1;">
					<button @click="printCancel">取消</button>
					<button @click="printSure">确认</button>
				</view>
			</view>
		</uni-popup>
		<!-- 打印修改 数量 弹出框 结束 -->


		<!-- 辅助数量 弹出框 开始 -->
		<uni-popup ref="fzPopup" type="center" :is-mask-click="false" :mask-click="false">
			<view class="fz_content">
				<view style="margin-bottom: 20upx;">商品多单位录入</view>
				<text @click="handleFzCancel" class="iconfont icon-guanbi"></text>
				<view>
					<t-table>
						<t-tr>
							<t-th style="flex:0 0 150upx;">项目</t-th>
							<t-th style="flex:0 0 150upx;">单位名称</t-th>
							<t-th style="flex:0 0 200upx;">数量</t-th>
							<t-th >单位关系</t-th>
						</t-tr>
						<t-tr v-for="(item, index) in selectFZList" :key="index" >
							<t-th style="flex:0 0 150upx;">{{ item.project }}</t-th>
							<t-th style="flex:0 0 150upx;">{{ item.unitName }}</t-th>
							<t-th style="flex:0 0 200upx;">
								<input type="number" @input="changeFzInput($event, index)" v-model.number="item.num" :disabled="item.disabled" :style="{background: !item.disabled ? '#169bd5' : '', color: !item.disabled ? '#fff' : ''}" />
							</t-th>
							<t-th>{{ item.unitContact }}</t-th>
						</t-tr>
					</t-table>
				</view>

				<view class="bottom_btn">
					<u-button @click="handleSureFz" >确定</u-button>
					<u-button @click="handleFzCancel" >取消</u-button>
				</view>
			</view>
		</uni-popup>
		<!-- 辅助数量 弹出框 结束 -->

		<!-- 配货数量  -->
		<uni-popup ref="phPopup" type="center" >
			<view class="ph_popup_content">
				<view class="title">配货数量</view>
				<view class="ph_content_info">
					<view style="display: flex;">
						<view style="white-space: nowrap; margin-right: 8rpx;">货号名称: </view>
						<view>{{ phPopupMap.materiel_name }}</view>
					</view>
					<view>配货数量: {{ phPopupMap.phquantity || 0 }}</view>
				</view>
				<view class="ph_footer">
					<button hover-class="hover_btn" @click="handlekczy('kczy')">库存转移</button>
					<button hover-class="hover_btn" @click="handlekczy('cpcfh')" class="cpcBtn" :style="{'background': phPopupMap.transferType == 'cpcfh' ? '#949090' : '#63a103' }">成品仓发货</button>
				</view>
			</view>
		</uni-popup>
		<!-- 配货数量  -->

	</view>
</template>

<script>
import { mapState } from 'vuex'

import customHeader from '@/components/custom-header/custom-header.vue'
import ruiDatePicker from '@/components/rattenking-dtpicker/rattenking-dtpicker.vue'
import customDownSearch from '@/components/custom-downSearch/custom-downSearch.vue'
import customPagination from '@/components/custom-pagination/custom-pagination.vue'
import tTable from '@/components/t-table/t-table.vue'
import tTh from '@/components/t-table/t-th.vue'
import tTr from '@/components/t-table/t-tr.vue'
import tTd from '@/components/t-table/t-td.vue'
import mySelectCheckbox from '@/components/my-selectCheckbox/my-selectCheckbox.vue'
import tsc from "@/util/tsc.js";

import { getInforList, getInfoDetail, getEmployee, editEmployee, editWork, getWorkteams, getOrdeNum, editRemark, getDetail_materiel, saveWorder_ph } from '@/api/modules/TVkanban.js'
	var timer_s = getNowFormatDate()
	var timer_e = getNowFormatDate()
	timer_s = timer_s.substring(0, 7) + "-01";

	function getNowFormatDate() {
		var date = new Date();
		var seperator1 = "-";
		var seperator2 = ":";
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		var currentdate = date.getFullYear() + seperator1 + month + seperator1 +
			strDate;
		return currentdate;

	}
	export default {
		components:{
			customHeader, 
			ruiDatePicker,
			customDownSearch,
			customPagination,
			tTable,
		    tTh,
		    tTr,
		    tTd,
			mySelectCheckbox,
		},
		data() {
			return {
				dates: timer_s,
				datee: timer_e,
				form: {
					zbinfo: [], // 组别信息 
					teamLeader:'', // 组长 
					members:'', // 组员 

					dqdds: '', // 当前订单数
					dqddNum: '', // 当前订单数量
					drwcNum: '', // 当日完成数量
					noNum: '', //未完成数量
					bzljcl: '', //本组累计产量
				},
				data1: [], // 生产信息列表
				data2: [], // 工单

				pageSize: 20, // 下单页数
				pageIndex: 1, // 当前页数
				totalCount: 1, // 应该有多少条数据

                showPopup: false, // 弹出框
				showBomPopup: false, // Bom 明细弹出框
				showNumPopup: false, // 完成数量弹出框
                popuptitle: '完成状态',
                statusList: [
                    { checked: false, labed: '已完成' },
                    { checked: false, labed: '未完成' },
                ], // 完成状态
				stateMap: {  // 订单状态
					'wmssoy_01': '待提交',
					'wmssoy_02': '待审核',
					'wmssoy_03': '待发货',
					'wmssoy_09': '已发货',
					'wmssoy_99': '已取消',
				},
				normalMap: { // 生产状态
					true: '正常',
					false: '异常',
				},
				completedMap: {
					true: '已完成',
					false: '未完成',
				},
				workOrderMap: { // 工单接口
					sorder_id: '',
					workteam_id: '', 
				},
				popupType: '', // 弹出框的状态类型
				data2_Map_item: {}, // 选中一条工单信息

				showToast: false, // 消息展示框
				showToastStr: '', // 提示框内容
				employeeList: [], // 员工数组
				selectEmployee: [], // 选中的员工数组

				zbinfoSelectList: [], // 组长 数组
				inputMemberList: [], // 获取组员数据
				zteamLeaderSelectList: [], // 组长 数组
				memberList: [], // 组员数组
				printList: [], // 打印数组

				ddNo: '', // 订单编号
				ddNum: '', // 订单 数量
				workteam_id: '', // 组别 id
				employeeName: '', // 模糊查询员工名字
				selectAll: false, // 全选按钮
				popupSelectEmployList: [], // 弹出框选中的员工数组
				showEdit: false, // 是否是编辑状态

				delNoList: [], // 要删除的订单编号
				delNoTimer: null,  // 删除单号

				deletionTimers: [], // 存储删除定时器的应用
				domList: [], // BOM 明细
				numPupopMap: {}, // 弹出框记录
				onDutyNum: 0, // 暂存完成数量
				printSl: 1, // 打印数量
				selectFZList: [], // 辅助数量
				showFzIndex: 0, // 辅助数量 弹出框 索引
				staffsList: [], // 员工信息
				compStateList: ['未完成', '已完成'],
				compSubStateList: ['全部','未完成', '已完成'],
				mainTable: '未完成',
				subTable: '全部',

				// 蓝牙打印使用
				looptime: 0,
				currentTime: 1,
				lastData: 0,
				oneTimeData: 0,
				buffSize: [],
				buffIndex: 0,
				printNum: [],
				printNumIndex: 0,
				printerNum: 1,
				currentPrint: 1,
				isLabelSend: false,
				isQuery: false,
				canvasWidth: 100,
				canvasHeight: 100,
				jpgWidth: 200,
				jpgHeight: 200,
				role: "",
				roleList: {},
				btnFlag: false,
				printArr: [],
				title: "",
				ids: "",
				ok_printer_sn: "",
				ydytitle: "",
				pz: 0,
				projectName: "",
				deviceId: '', // 设备 id 蓝牙使用
				active_menu_id: '', // 当前选中的菜单
				phPopupMap: {}, 
			}
		},
		async onLoad(r) {
			this.active_menu_id = r.id
			await this._getWorkteams() // 顶部 input 组员信息
			// await this._getInforList()  // 生产信息列表  1
			await this._getEmployee()
			// await this._getInfoDetail(); // 订单生产明细
			uni.removeStorageSync('BLEInformation');

			this.getEmployeePopup()
		},
		onReady() { // 打印使用
			var list = [];
			var numList = [];
			var j = 0;

			for (var i = 20; i < 200; i += 10) {
				list[j] = i;
				j++;
			}

			for (var i = 1; i < 10; i++) {
				numList[i - 1] = i;
			}

			this.setData({
				buffSize: list,
				oneTimeData: list[0],
				printNum: numList,
				printerNum: numList[0],
			});
		},
		
		computed: {
			...mapState(['sideList', 'indexList']),
		},
		watch: {
			employeeList: {
				handler(newVal, oldVal) {
					if (newVal.length == 0) {
						this.selectAll = false
						return
					}
					if (newVal.every(i => i.checked)) {
						this.selectAll = true
					} else {
						this.selectAll = false
					}
				},
				immediate: true,
				deep: true
			},
		},
		methods: {
			// 计算子表的 辅助数量转换关系
			getFzSl(ddsl, fzsl) {
				// 数据验证和转换
				const d = Number(ddsl) || 0
				const f = Number(fzsl) || 0
				
				// 处理异常情况
				if (d <= 0) {
					return '0PCS'
				}
				if (f <= 0) {
					return d + 'PCS'
				}
				if (isNaN(d) || isNaN(f)) {
					return '0PCS'
				}
				
				// 计算整数部分和余数
				const integerPart = Math.floor(d / f)
				const remainder = d % f
				
				// 根据计算结果返回不同格式
				if (integerPart === 0) {
					// 小于1件的情况
					return d + 'PCS'
				} else if (remainder === 0) {
					// 正好整数件的情况
					return integerPart + '件'
				} else {
					// 有整数件和余数的情况
					let num = remainder.toFixed(0)
					return integerPart + '件' + (num > 0 ?  num + 'PCS' : '')
				}
			},
			clearEmploy() {
				this.staffsList = this.staffsList.map(i => ({ ...i, checked: false }))
				uni.showToast({
					title: "已清空勾选项",
					icon: 'none',
					duration: 2000,
				})
			},
			selectEmploySure() {
				let employeeList = this.staffsList.filter(i => i.checked)
				this.numPupopMap = {
					...this.numPupopMap,
					employNameStr: employeeList.map(i => i.name).join(','),
					employIdStr: employeeList.map(i => i.id).join(',')
				}
				this.$refs.employPopup.close()
			},
			selectEmployClose() {
				this.$refs.employPopup.close()
			},
			selectEmploy(item) {
				item.checked = !item.checked
			},
			// 弹出框 选择员工
			handleEmploy1() {
				let idList = (this.numPupopMap.employIdStr || '').split(',')
				this.staffsList = this.staffsList.map(i => ({
					...i,
					checked: idList.filter(j => j == i.id).length > 0
				}))
				this.$refs.employPopup.open('center')
			},
			// 配货数量
			handlePhsl(item) {
				console.log('== 配货数量 ', item)
				this.phPopupMap = item
				if (item.phquantity <= 0) return
				this.$refs.phPopup.open('center')
			},
			// 配货库存转移
			async handlekczy(type) {
				// kczy 库存转移；cpcfh 成品仓发货
				let param = {
					id: this.phPopupMap.id,
					type,
				}

				const res = await saveWorder_ph(JSON.stringify(param))
				const { data: { status, message } } = res || {}
				if (status == 'success') {
						uni.showToast({
							title: "修改成功!",
							icon: 'none',
							duration: 2000,
						})
						this.$refs.phPopup.close()
						await this._getInfoDetail() // 先返回数据
					} else if (status == 'fail') {
						uni.showToast({
							title: message,
							icon: 'none',
							duration: 2000,
						})
					}
				console.log('== 库存转移 ', res)
			},
			handleSureFz() {
				let selectItem = this.selectFZList.filter(i => i.num > 0)
				console.log('== 确认 ', selectItem, this.showFzIndex)
				if (!selectItem.length) {
					uni.showToast({
						title: '请输入数量!',
						icon: 'none',
						duration: 1500
					})
					return
				}
				let num = selectItem[0].num || 0
				let unitContact = selectItem[0].unitContact || 0
				let sum = num * unitContact
				// this.data2[this.showFzIndex].materiel_rate2 = sum

			},
			handleFzCancel() {
				this.$refs.fzPopup.close()
			},
			changeFzInput(e, index) {
				let value = Number(e.target.value)
				let cloneMap = JSON.parse(JSON.stringify(this.selectFZList))
				if (value > 0) {
					this.selectFZList = cloneMap.map((i, j) => ({...i, disabled: true }))
					this.selectFZList[index].disabled = false
				} else {
					this.selectFZList = cloneMap.map((i, j) => ({...i, disabled: false }))
				}
			},
			handlefzPup(item, index) {
				this.selectFZList = [
					{ project: '基本单位', unitName: item.materiel_unit_text, num: 0, disabled: false, unitContact: 1 },
					{ project: '辅助单位1', unitName: item.materiel_unit1_text , num: 0, disabled: false, unitContact: item.materiel_rate1 },
					{ project: '辅助单位2', unitName: item.materiel_unit2_text, num: 0, disabled: false, unitContact: item.materiel_rate2 },
				]
				this.showFzIndex = index
				this.$refs.fzPopup.open('center')
			},

			handlePrintPopupBox() {
				let selectList = this.data2.filter(item => item.mxCheck)
				console.log('== selectList', selectList)
				if (!selectList.length) {
					uni.showToast({
						title: '请勾选要打印的数据!',
						icon: 'none',
						duration: 1500
					})
					return
				}
				this.printList = selectList.map(i => ({...i, printSl: 1 }))
				this.$refs.printPopup.open('center')
			},
			changeMxBox(item) {
				item.mxCheck = !item.mxCheck
			},
			printSure() {
				let lyName = uni.getStorageSync('BLEInformation')
				if (!this.printSl) {
					uni.showToast({
						title: '请输入数量',
						icon: 'none',
						duration: 1500
					})
					return
				}
				this.deviceId = lyName?.deviceId || ''
				if (!lyName) {
					uni.showToast({
						title: '请先连接蓝牙',
						icon: 'none'
					})
					uni.showModal({
						title: '提示',
						content: '请先连接蓝牙',
						success: function (res) {
							if (res.confirm) {
								uni.navigateTo({
										url: '../printSet/printSet'
								});
							}
						}
					});
					return
				}


				// let arr = []
				// let arr1 = this.data2.filter(j => j.mxCheck).map(i => ({
				// 	pm: i.materiel_name,
				// 	no: i.materiel_no,
				// 	spec: i.materiel_spec,
				// 	sl: i.materiel_rate2,
				// 	materiel_unit_text: i.materiel_unit_text,
				// 	employNumStr: (i.staffs || []).map(x => x.no).join('-')
				// }))
				// for (let i = 0; i < this.printSl; i++) {
				// 	arr = arr.concat(arr1)
				// }

				let arr = []
				let arr1 = this.printList.map(i => ({
					pm: i.materiel_name,
					no: i.materiel_no,
					spec: i.materiel_spec,
					sl: i.materiel_rate2,
					materiel_unit_text: i.materiel_unit_text,
					employNumStr: (i.staffs || []).map(x => x.no).join('-'),
					printSl: i.printSl
				}))
				arr1.forEach(item => {
					let printSl = parseInt(item.printSl, 10);
					for (let i = 0; i < printSl; i++) {
						arr.push({...item});
					}
				});
				this.printCancel()
				this.printSingleItem(arr)
			},
			printCancel() {
				this.$refs.printPopup.close()
			},
			
			printSingleItem(arr) {  
				var command = tsc.jpPrinter.createNew();
				arr.forEach((item, index) => {
					command.setCls();
					command.setSize(70, 50);
					command.setGap(2);
					command.setCls();
					command.setBox(0, 10, 520, 380, 2); //绘制一个边框
					command.setBar(70, 10 , 2, 370) //  竖线 

					command.setBar(0, 200 , 520, 2) //  横线 

					command.setBar(0, 250 , 330, 2) //  横线 
					command.setBar(0, 295 , 330, 2) //  横线 

					command.setBar(0, 340 , 520, 2) //  横线 
					
					command.setBar(330, 200 , 2, 140) //  竖线 
					command.setText(4, 100, "TSS24.BF2", 0, 1, 1, `品名:`);
					if ( item.pm.length > 54 ) {
						command.setText(75, 10, "TSS24.BF2", 0, 1, 2, item.pm.substring(0, 18));
						command.setText(75, 10 + 50, "TSS24.BF2", 0, 1, 2, item.pm.substring(18, 36));
						command.setText(75, 10 + 50 * 2, "TSS24.BF2", 0, 1, 2, item.pm.substring(36, 54));
						command.setText(75, 10 + 50 * 3, "TSS24.BF2", 0, 1, 2, item.pm.substring(54));
					} else if (item.pm.length > 36) {
						command.setText(75, 50, "TSS24.BF2", 0, 1, 2, item.pm.substring(0, 18));
						command.setText(75, 50 + 50, "TSS24.BF2", 0, 1, 2, item.pm.substring(18, 36));
						command.setText(75, 50 + 50 * 2, "TSS24.BF2", 0, 1, 2, item.pm.substring(36, 54));
					}  else if (item.pm.length > 18) {
						command.setText(75, 75, "TSS24.BF2", 0, 1, 2, item.pm.substring(0, 18));
						command.setText(75, 75 + 50, "TSS24.BF2", 0, 1, 2, item.pm.substring(18, 36));
					}   else {
						command.setText(75, 90, "TSS24.BF2", 0, 1, 2, item.pm.substring(0, 18));
					}


					command.setText(4, 215, "TSS24.BF2", 0, 1, 1, `品号:`);
					command.setText(75, 215, "TSS24.BF2", 0, 1, 1, `${item.no}`);

					command.setText(4, 260, "TSS24.BF2", 0, 1, 1, `规格:`);
					command.setText(75, 260, "TSS24.BF2", 0, 1, 1, `${item.spec}`);

					command.setText(4, 305, "TSS24.BF2", 0, 1, 1, `数量:`);
					command.setText(75, 305, "TSS24.BF2", 0, 1, 1, `${item.sl} ${item.materiel_unit_text}`);

					command.setText(4, 350, "TSS24.BF2", 0, 1, 1, `时间:`);
					command.setText(75, 350, "TSS24.BF2", 0, 1, 1, this.getCurrentTime());

					command.setText(200, 350, "TSS24.BF2", 0, 1, 1, `工号:`);
					command.setText(260, 350, "TSS24.BF2", 0, 1, 1, `${item.employNumStr}`);

					command.setQrcode(360, 210, "L", 6, 'A', item.no + ',' + item.sl); // 绘制二维码
					command.setPagePrint(); //执行打印指令
					this.setData({
						isLabelSend: true,
					});
				})
				let userInfo = {
					deviceId: this.deviceId,
					serviceId: '49535343-FE7D-4AE5-8FA9-9FAFD205E455',
					characteristicId: '49535343-8841-43F4-A8D4-ECBE34729BB3',
				}
				
				setTimeout(() => {
					// this.prepareSend(command.getData());

					this.senBlData(userInfo.deviceId, userInfo.serviceId, userInfo.characteristicId, command.getData())
				}, 500);
			},
			getCurrentTime() {
				// 获取当前时间
				const now = new Date();

				// 获取各个部分的时间信息
				const year = now.getFullYear();
				const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
				const day = String(now.getDate()).padStart(2, '0');
				const hours = String(now.getHours()).padStart(2, '0');
				const minutes = String(now.getMinutes()).padStart(2, '0');
				const seconds = String(now.getSeconds()).padStart(2, '0');

				// 拼接成指定格式：YYYY-MM-DD HH:mm:ss
				// return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
				return `${year}-${month}-${day}`;
			},
			handleNumRecords(item) {
				console.log('== 22 ', item)
				console.log('== 33 ', item.reportDtl)
				// console.log('== 44 ', item.reportDtl.staffs)
				this.numPupopMap = {}
				this.numPupopMap = {
					...item,
				}

				// 添加对 staffs 及其元素的检查
				if (item.staffs && item.staffs.length > 0) {
					this.numPupopMap.employNameStr = item.staffs.map(staff => staff.name).join(',')
					this.numPupopMap.employIdStr = item.staffs.map(staff => staff.id).join(',')
					// let newIndex = item.reportDtl.length - 1
					// const latestReport = item.reportDtl[newIndex]
					// if (latestReport && latestReport.staffs) {
					// 	this.numPupopMap.employNameStr = latestReport.staffs.map(staff => staff.name).join(',')
					// 	this.numPupopMap.employIdStr = latestReport.staffs.map(staff => staff.id).join(',')
					// } else {
					// 	this.numPupopMap.employNameStr = ''
					// 	this.numPupopMap.employIdStr = ''
					// }
				} else {
					this.numPupopMap.employNameStr = ''
					this.numPupopMap.employIdStr = ''
				}
				this.onDutyNum = item.differenceNum // 暂存完成数量
				this.$refs.complNumPopup.open('center')
			},
			handleCancelNum() {
				this.$refs.complNumPopup.close()
				this.numPupopMap.differenceNum = this.onDutyNum
			},
			async handleNumPopup() {
				let param = {
					no: this.numPupopMap.no,
					sorderi_id: this.numPupopMap.sorderi_id,
					cquantity: this.numPupopMap.differenceNum,
					id: this.numPupopMap.id,
					staffs: this.numPupopMap.employIdStr.split(',').map(i => ({id: i}))
				}
				if (!this.numPupopMap.employIdStr.length) {
					param.staffs = []
					uni.showToast({
						title: '请选择员工!',
						icon: 'none',
						duration: 1500
					})
					return 
				}
				let res = await editWork(JSON.stringify([param]))
				const  { data: { data, message, status	 } } = res || {}
				if ( status == 'success' ) {
					uni.showToast({
						title: '修改成功',
						icon: 'none',
						duration: 1500
					})
					setTimeout(async () => {
						this.$refs.complNumPopup.close()
						await this._getInfoDetail() // 先返回数据
					}, 1500)
				} else if (status === 'fail') {
					uni.showToast({
						title: message,
						icon: 'none',
						duration: 1500
					})
					await this._getInfoDetail() // 先返回数据
				}
				
			},
			async handleBomPopup(id) {
				this.domList = []
				const res = await getDetail_materiel(JSON.stringify({ id: id }))
				const { data, status, summary } = res.data || {}
				if (status == 'success') {
					this.showBomPopup = true
					const { bom } = data || {}
					const { bomis } = bom || {}
					this.domList = (bomis || [])
				} else {
					uni.showToast({
						title: summary,
						icon: 'none',
						duration: 2000,
					})
				}
			},
			async handleEdit() { // 修改删除备注
				if (this.showEdit) {
					let newData = this.data2.map(i => ({ no: i.no, remark: i.remark, id: i.id }))
					const res = await editRemark(JSON.stringify(newData))
					// console.log('== res', res)
					const { data: { status, message } } = res || {}
					if (status == 'success') {
						uni.showToast({
							title: "修改成功!",
							icon: 'none',
							duration: 2000,
						})
						this.showEdit = !this.showEdit
					} else if (status == 'fail') {
						uni.showToast({
							title: message,
							icon: 'none',
							duration: 2000,
						})
					}

				} else {
					this.showEdit = !this.showEdit
				}
			},
			handleSearchGroupEmployees() {  // 查询本组员工数据
				this._getEmployee(this.employeeName, this.workteam_id)
			},
			mergeAndDeduplicateById(arr1, arr2) {
				let uniqueArr1 = arr1.filter(item1 => !arr2.some(item2 => item1.id ===item2.id))
				const mergedArray = [...arr2, ...uniqueArr1];  
				return mergedArray;  
			},
			changeAll() {
				this.selectAll = !this.selectAll
				if (this.selectAll) {
					this.employeeList = JSON.parse(JSON.stringify(this.employeeList)).map((i, j) => ({...i, checked: true}))
					this.popupSelectEmployList = JSON.parse(JSON.stringify(this.employeeList))
				} else if (!this.selectAll) {
					this.employeeList = JSON.parse(JSON.stringify(this.employeeList)).map((i, j) => ({...i, checked: false}))
					this.popupSelectEmployList = JSON.parse(JSON.stringify(this.employeeList))
				}
			},
			async queryName() {
				this._getEmployee(this.employeeName)
			},
			changeZbinfo(e) {
				this.workteam_id = e
				let selectItem = this.inputMemberList.filter(i => i.id == e)[0]
				this.form.teamLeader = selectItem?.leader_name
				this.form.members = selectItem?.members.map(i => i.name).join(',')
				this._getInforList() // 调用接口 第一个表格
				if (e) {
					this._getOrdeNum(e) // 获取 input 订单数量
				} else {
					this.form = {
						zbinfo: [], // 组别信息 
						teamLeader:'', // 组长 
						members:'', // 组员 
						dqdds: '', // 当前订单数
						dqddNum: '', // 当前订单数量
						drwcNum: '', // 当日完成数量
						noNum: '', //未完成数量
						bzljcl: '', //本组累计产量
					}
				}
			},
			changeMember(e) {
				console.log('=== 组员', e)
			},
			handleScroll1() {
				if ( this.pageIndex <= this.totalCount ) {
					this._getInforList(true)
				} else {
					uni.showToast({
						title: '没有更多数据了',
						duration: 2000,
						icon: 'none'
					});
				}
			},
			handleItem(item, index) {  // 切换 table 表格的
				this.data1 = JSON.parse(JSON.stringify(this.data1)).map((i, j) => ({...i, active: j == index ? true : false}))
				this.workOrderMap = { sorder_id: item.id , workteam_id: this.workteam_id , stopSchedule: 'false' }
				this.employeeList = JSON.parse(JSON.stringify(this.employeeList)).map(i => ({...i, checked: false}))
				this._getInfoDetail()
			},
			checkboxChange(e) {
				this.selectEmployee = e.detail.value
				// 点击选中员工的时候需要保持勾选
				this.popupSelectEmployList = this.employeeList.filter(i => this.selectEmployee.includes(i.no))
				let arr = JSON.parse(JSON.stringify(this.employeeList))
				arr.forEach(i => {
					if (e.detail.value.includes(i.no)) {
						i.checked = true
					} else {
						i.checked = false
					}
				})
				this.employeeList = arr
            },
            radioChange(e) {
				this.popupType = e.detail.value
            },
            handleEmployee(item, index) {
				this.popupSelectEmployList = item.staffs
                this.showPopup = true;
                this.popuptitle = '员工信息'
				let newList = this.employeeMatchId(item.staffs, this.employeeList)
				this.employeeList = JSON.parse(JSON.stringify(newList))
				this.data2_map_item = {
					id: item.id,
					no: item.no,
				}
            },
            handleStatus(item, index) {
                this.showPopup = true;
                this.popuptitle = '完成状态'

				let statu = this.completedMap[item.completed]
				this.statusList = JSON.parse(JSON.stringify(this.statusList)).map((i, j) => ({...i, checked: i.labed == statu ? true : false }))
				this.data2_Map_item = item

            },
			handleCancel() {
				this.showPopup = false
				this.employeeList = JSON.parse(JSON.stringify(this.employeeList)).map(i => ({...i, checked: false}))
				this.employeeName = ''
			},
			async confirmEmployee() {
				// let list = this.employeeList.filter(i => this.selectEmployee.includes(i.no)).map(i => ({ id: i.id, no: i.no, name: i.name }))
				let list = this.employeeList.filter(i => i.checked).map(i => ({ id: i.id, no: i.no, name: i.name }))

				let param = [{
					...this.data2_map_item,
					staffs: list
				}]

				const res = await editEmployee(JSON.stringify(param))
				const  { data: { data, message, status	 } } = res || {}

				if ( status == 'success' ) {
					this.showPopup = false;
					this.changeData('修改成功')
					this._getInfoDetail()
				} else if (status === 'fail') {
					this.changeData(message)
				}
				
			},

			async confirmStatus() { // 状态的弹出框
				let param = [{
					id: this.data2_Map_item.id,
					no:  this.data2_Map_item.no,
					cquantity: this.data2_Map_item.yquantity,
				}]

				const res = await editWork(JSON.stringify(param))

				const  { data: { data, message, status	 } } = res || {}
				if ( status == 'success' ) {
					this.showPopup = false;
					this.changeData('修改成功')
					await this._getInfoDetail() // 先返回数据
					// this._getInforList()
					await this.delComItem()  // 异步处理
				} else if (status === 'fail') {
					this.changeData(message)
				}

			},
			delComItem() {
				// 判断子表的完成状态全部要都是 true
				if (this.data2.filter(i => i.completed)?.length == this.data2.length) {
					let newIndex = this.data1.findIndex(i => i.no == this.data1.filter(i => i.active)[0]?.no)
					
					// 修改主表的状态
					this.data1 = JSON.parse(JSON.stringify(this.data1)).map(i => ({
						...i,
						completed: i.active ? true : i.completed // 3.变成已完成
					}))

					this.deletionTimers[newIndex] = setTimeout(() => { // 3.删除数据 60 秒后
						this.data1 = JSON.parse(JSON.stringify(this.data1)).filter(i => i.no !== this.deletionTimers[newIndex].split('bao_^_*')[1])

						// this._getInforList()
					}, (1000 * 60)) + 'bao_^_*' + this.data1.filter(i => i.active)[0]?.no
				}
			},
            handleOpen() {
                this.showPopup = true
            },
			handleSearch() {
				const {  zbinfo, teamLeader, members, dqdds, dqddNum, drwcNum, noNum, bzljcl } = this.form
			
				let param = {
					startdate: this.dates,
					enddate: this.datee,

					zbinfo: zbinfo, // 组别信息 
					teamLeader: teamLeader, // 组长 
					members: members, // 组员 

					dqdds: dqdds, // 当前订单数
					dqddNum: dqddNum, // 当前订单数量
					drwcNum: drwcNum, // 当日完成数量
					noNum: noNum, //未完成数量
					bzljcl: bzljcl, //本组累计产量
				}
			},
			changeMainTable(e) {
				this.mainTable = e
				this.pageIndex = 1
				this._getInforList()
			},
			inputMainTable(e) {
			},
		   
			async _getInforList( type ) { //  // 生产信息列表  1
				let param = {
					paging: {
						pageIndex: this.pageIndex,
						pageSize: 20,
					},
					query: {
						workteam_id: this.workteam_id,
						completed: false,
						active_menu_id: this.active_menu_id, // 菜单id
						// workteam_id: 4,
						// startdate: this.dates,
						// enddate: this.datee,
						completed: this.mainTable == '已完成' ? 'true' : 'false',
					}
				}
				const res = await getInforList(JSON.stringify(param))
				// console.log('== res 订单列表', res)

				const { data: { data, message, status	 } } = res || {}

				if (status == 'success') {
					this.data1 = data.sorders.map((i, j) => ({...i, state: this.stateMap[i.state], active: j == 0 ? true : false}))

					if (type) {
						let newData = this.data1
						this.data1 = newData.concat(  data.sorders.map((i, j) => ({...i, state: this.stateMap[i.state], active: false})) )
					} else {
						this.data1 = data.sorders.map((i, j) => ({...i, state: this.stateMap[i.state], active: j == 0 ? true : false}))
					}

					this.workOrderMap = { sorder_id: (data.sorders.length ? data.sorders[0]?.id : '') , workteam_id: this.workteam_id, stopSchedule: 'false'  }
					this._getInfoDetail() // 第二张表格

					// 上划加载更多
					let totalPage = Math.ceil(data.paging.total / 20)
					this.totalCount = totalPage
					// if (totalPage > this.pageIndex) {
					// 	this.pageIndex++
					// }

					if (data.paging.pageIndex == this.pageIndex) {
						this.pageIndex++
					}

				} else if (status === 'fail') {
					uni.showToast({
						title: message,
						duration: 2000,
						icon: 'none'
					});
				} 
			},

			async _getEmployee( str = '', id = '' ) {
				let param = {
					paging: {
						pageIndex: 1,
						pageSize: 20,
					},
					query: {
						// workteam_id: this.workteam_id,
						workteam_id: id, // 指定班组id
						valid: true,
						search: str,
					}
				}
				const res = await getEmployee(JSON.stringify(param))

				const { data: { data, message, status	 } } = res || {}

				if (status == 'success') {

					if (id) { // 查询本组员工
						let arr2 = this.mergeAndDeduplicateById(this.employeeList, data.staffs.map(i => ({...i, checked: true})))
						this.employeeList = JSON.parse(JSON.stringify(arr2))
						return
					}

					this.employeeList = data.staffs.map(i => ({...i, checked: false}))
					
					// if (str.length) {
					// 	if (!this.employeeList.filter(i => data.staffs.some(j => i.id == j.id)).length) {
					// 		this.employeeList.unshift(...data.staffs.map(i => ({...i, checked: false})))
					// 	}
					// } else {
					// 	if (this.popupSelectEmployList.length) {
					// 		let newList = this.mergeAndDeduplicateById(this.popupSelectEmployList, this.employeeList)
					// 		this.employeeList = JSON.parse(JSON.stringify(newList))
					// 	} else {
					// 		this.employeeList = data.staffs.map(i => ({...i, checked: false}))
					// 	}
					// }

					if ( !data.staffs.length ) {
						this.changeData('查找不到该员工!')
					}
				} else if (status === 'fail') {
					uni.showToast({
						title: message,
						duration: 2000,
						icon: 'none'
					});
				}


			},

			// 获取员工列表 
			async getEmployeePopup() {
				let param = {
					paging: {
						pageIndex: 1,
						pageSize: 20000,
					},
					query: {
						valid: true,
						onduty: 'onDuty',
					}
				}
				const res = await getEmployee(JSON.stringify(param))
				const { data } = res.data || {}
				const { staffs } = data || {}
				this.staffsList = (staffs || []).map(i => ({
					...i,
					checked: false
				}))
			},
			changeSubTable(e) {
				this.subTable = e
				this._getInfoDetail()
			},
			inputSubTable(e) {},
			async _getInfoDetail() { // 工单明细
				this.data2 = []
				let param = {
					...this.workOrderMap,
					completed: this.subTable == '已完成' ? 'true' : 'false',
				}
				if (this.subTable == '全部') {
					delete param.completed
					// param.completed = ''
				}
				const res = await getInfoDetail(JSON.stringify(param))
				const  { data: { data, message, status	 } } = res || {}
				if ( status == 'success' ) {
					this.data2 = data.worders.map(i => ({
						...i, state: this.stateMap[i.state], 
						staffsStr:  i.staffs.map(i => i.name).join('、'),
						differenceNum: (Number(i.yquantity) || 0) - (Number(i.phquantity) || 0) - (Number(i.scquantity) || 0),
						mxCheck: false,
					}))
					this.ddNo = data.no
					this.ddNum = data.total

				} else if (status === 'fail') {
					uni.showToast({
						title: message,
						duration: 2000,
						icon: 'none'
					});
				} 
			},
			async _getWorkteams() {  // 获取班组信息
				let param = {
					paging: {
						pageIndex: 1,
						pageSize: -1,
					},
					query: {
						valid: true,
						search: ''
					}

				}
				const res = await getWorkteams(JSON.stringify(param))

				const  { data: { data, message, status	 } } = res || {}

				if ( status == 'success' ) {
					this.zbinfoSelectList = data.workteams.map(i => ({ name: i.name, id: i.id }))
					this.zteamLeaderSelectList = data.workteams.map(i => ({ leader_name: i.leader_name, leader_id: i.leader_id }))

					this.memberList = (data.workteams[0]?.members || [])
					this.inputMemberList = data.workteams
					if (this.zbinfoSelectList.length) {
						this.workteam_id = this.zbinfoSelectList[0].id
						this.form.zbinfo = this.zbinfoSelectList[0].id
						this.form.teamLeader = data.workteams[0].leader_name
						this.form.members = data.workteams[0].members.map(i => i.name).join(',')
					}
					this._getInforList() // 调用接口 第一个表格

					this._getOrdeNum() // 获取用户信息接口

				} else if (status === 'fail') {
					uni.showToast({
						title: message,
						duration: 2000,
						icon: 'none'
					});
				}
			},
			async _getOrdeNum(id) {
				const param = {
					workteam_id: this.workteam_id,
				}
				const res = await getOrdeNum(JSON.stringify(param))
				const  { data: { data, message, status	 } } = res || {}
				if ( status == 'success' ) {
					this.form = {
						...this.form,
						dqdds: data.sorder_num,
						dqddNum: data.sorder_qty,
						drwcNum: data.comp_qty,
						noNum: data.unf_qty,
						bzljcl: data.total,
					}
				} else if (status === 'fail') {
					uni.showToast({
						title: message,
						duration: 2000,
						icon: 'none'
					});
				}
			},
			/**
			 * 匹配员工数组，将arr1中的员工在arr2中标记为已选中
			 * @param {Array} arr1 - 已选中的员工数组
			 * @param {Array} arr2 - 所有员工数组
			 * @returns {Array} - 更新后的员工数组
			 */
			employeeMatchId(arr1, arr2) {
				// 深拷贝arr2，避免修改原数组
				let newData = JSON.parse(JSON.stringify(arr2));
				
				// 先将所有员工标记为未选中
				newData.forEach(employee => {
					employee.checked = false;
				});
				
				// 遍历已选中的员工数组
				arr1.forEach(selectedEmployee => {
					// 在newData中查找对应的员工
					const matchingEmployee = newData.find(employee => employee.id === selectedEmployee.id);
					
					// 如果找到匹配的员工，标记为已选中
					if (matchingEmployee) {
						matchingEmployee.checked = true;
					}
				});
				
				return newData;
			},
			changeData(param) {  // img 信息弹出框
				this.showToast = true;
				this.showToastStr = param
				this.timer = setTimeout(() => {
					this.showToast = false;
					clearTimeout(this.timer)
				}, 3000)
			},
			// 蓝牙方法
			senBlData(deviceId, serviceId, characteristicId, uint8Array) {
				// 检查数据格式
				if (!uint8Array || !uint8Array.length) {
					uni.showToast({
						title: '打印数据为空',
						icon: 'none'
					});
					return;
				}
				
				var uint8Buf = Array.from(uint8Array);
				function split_array(datas, size) {
					var result = {};
					var j = 0
					for (var i = 0; i < datas.length; i += size) {
						result[j] = datas.slice(i, i + size)
						j++
					}
					return result
				}

				var sendloop = split_array(uint8Buf, 20);
				var currentPacket = 0;
				
				function realWriteData(sendloop, i) {
					var data = sendloop[i]
					if (typeof(data) == "undefined") {
						// 所有分包发送完成，显示成功提示
						uni.showToast({
							title: "打印成功",
						});
						return
					}
					
					var buffer = new ArrayBuffer(data.length)
					var dataView = new DataView(buffer)
					for (var j = 0; j < data.length; j++) {
						dataView.setUint8(j, data[j]);
					}
					
					uni.writeBLECharacteristicValue({
						deviceId,
							serviceId,
							characteristicId,
							value: buffer,
							success(res) {
								currentPacket++;
								// 添加延迟，避免发送太快
								setTimeout(() => {
									realWriteData(sendloop, i + 1);
								}, 50); // 50ms延迟
							},
							fail(err) {
								console.error('蓝牙写入失败:', err);
								uni.showToast({
									title: "打印失败",
									icon: "none"
								});
							},
							complete: (err) => {
								if (err) {
									console.error('蓝牙写入完成但有错误:', err);
								}
							}
						})
				}
				var i = 0;
				realWriteData(sendloop, i);
			},
			
			// 蓝牙方法
		}
	}
</script>

<style lang="less" scoped>
.content {
	height: 100vh;
	display: flex;
	flex-direction: column;

	.refreshBtn {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0;
		margin-left: 20rpx;
		background: #18aff2;
		color: #fff;
		height: 60rpx;
	}

	.hover_refresh {
		background: #169fda;
	}

	.top {
		width: 100%;
		z-index: 12;
	}

	.bao_td_left {
		width: 100%;
		height: 100%;
		text-align: left;
	}

	.center {
		padding: 0 40rpx;
		flex: 1;
		display: flex;
		flex-direction: column;

		/* 隐藏滚动条 
		::-webkit-scrollbar {
			display: none;
		}
		-ms-overflow-style: none;
		scrollbar-width: none;
		*/

		.search_content {
			display: flex;
			align-items: center;
			justify-content: space-between;
			.item_search {
				display: flex;
				align-items: center;
				height: 60rpx;

				.title {
					font-size: 40rpx;
					font-weight: 700;
					margin-right: 30rpx;
					white-space: nowrap;
				}
                .input {
                    flex: 1; 
                    height: 30rpx; 
                    border: 1rpx solid #ccc; 
                    font-size: 30rpx;
                    padding: 12rpx 8rpx; 
                }
			}
		}

		.search_btn {
			display: flex;
			justify-content: space-between;
			margin: 30rpx;

			button {
				width: 360rpx;
				color: #fff;
				margin: 0;
				font-size: 50rpx;
			}

			button:nth-child(1) {
				background: red;
			}
			button:nth-child(2) {
				background: #f59a23;
			}
		}
		
		.table_content {
			// height: calc(100vh - 1400rpx);
			min-height: 400rpx;
			max-height: 500rpx;
			// height: calc(100vh - 1588rpx);
			width: 100%;
			// background: red;
		}

		.bottom_contetn {
			margin-top: 40rpx;
			font-size: 34rpx;

			.none {
				border: none;
			}
		}

        .center_1 {
            display: flex;
            padding: 20rpx 0;

            .center_item {
                display: flex;
                align-items: center;
                .item_title {
                    font-size: 40rpx;
                    font-weight: 700;
                    margin-right: 20rpx;
                }
            }

			.bao_btn {
				display: flex;
				align-items: center;
				margin-left: 60rpx;

				button {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 160rpx;
					height: 60rpx;
					background: #18aff2;
					color: #fff;
					border-radius: 10rpx;
					font-size: 30rpx;
				}

				.btn_hover {
					background: #1392c9 !important;
				}
			}
        }
        .table_2_content {
            width: 125%;
            // height: calc(100vh - 1240rpx);
            min-height: 400rpx;
            max-height: 500rpx;
			// background: skyblue;
        }
	}


    .popup_content {
        width: 800rpx;
        // height: 900rpx;
        background: #fff;
        padding: 60rpx;
		border-radius: 55rpx;

		.toast {
			position: absolute;
			top: 140rpx;
			left: 400rpx;
			
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 40rpx;
			border-radius: 15rpx;
			background: #575757;
			color: #fff;
			font-size: 30rpx;

			.toast_msg {
				max-height: 600rpx;
				max-width: 1000rpx;
				overflow: auto;
			}
		}

        .title {
            font-size: 56rpx;
            font-weight: 700;
        }

        .popup_search {
            display: flex;
            align-items: center;
            margin-top: 20rpx;

            input {
                border: 1rpx solid #ccc;
                padding: 12rpx 8rpx;
                margin-right: 100rpx;
            }
            button {
                display: flex;
                align-items: center;
                justify-content: center;
                margin: 0px;
                height: 80rpx;
                color: #fff;
                background: #008fe0;
            }
        }

		.selectAll_content {
			display: flex;
            align-items: center;
            margin-top: 20rpx;

			button {
                display: flex;
                align-items: center;
                justify-content: center;
                margin: 0px;
                height: 80rpx;
                color: #fff;
                background: #008fe0;
				margin-left: 320rpx;
            }
		}


        .checked_content {
            border: 1rpx solid #ccc;
            padding: 10rpx;
            margin-top: 20rpx;

            .table_3_content {
                height: 500rpx;

                .label_item {
                    display: flex;
                    align-items: center;
                    margin-bottom: 10rpx;
                }
            }
        }

        .popup_btn {
            display: flex;
            justify-content: flex-end;
            margin-top: 40rpx;
            button {
                display: flex;
                align-items: center;
                justify-content: center;
                margin: 0px;
                height: 66rpx;
                width: 300rpx;
            }
            button:nth-child(1) {
                color: #fff;
                background: #008fe0;
                margin-right: 20rpx;
            }
            button:nth-child(2) {
                color: #008fe0;
                border: 1rpx solid #008fe0;
                background: #fff;
            }
        }
    }

	.Bom_popup_comtent {
		width: 80vw;
		max-height: 80vh;
		padding: 40rpx;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		position: relative;
		background: #fff;

		.title {
			font-size: 40rpx;
			font-weight: bold;
			text-align: center;
		}

		.bom_bottom {
			display: flex;
			align-items: center;
			justify-content: space-around;
			padding-top: 20rpx;
		}

		button {
			margin: 0;
			width: 240rpx;
			background: #18aff2;
			color: #fff;
		}

		.hover_btn {
			background: #1497cf;
		}

		.toast {
			position: absolute;
			top: 50%;
			left: 50%;
			
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 40rpx;
			border-radius: 15rpx;
			background: #575757;
			color: #fff;
			font-size: 30rpx;

			.toast_msg {
				max-height: 600rpx;
				max-width: 1000rpx;
				overflow: auto;
			}
		}
	}

    .btn {
        color: #d6d5d5 !important;
        background: #006faf !important;
    }
    .btn1 {
        color: #0374b6 !important;
        background: #d3d3d3 !important;
    }

	// 打印弹出框样式
	.print_popup {
		width: 800rpx; 
		min-height: 300rpx; 
		height: 800rpx;
		background: #fff; 
		border-radius: 20rpx; 
		padding: 10rpx; 
		display: flex; 
		flex-direction: column;
		font-size: 40rpx;

		.dis_flex {
			display: flex;
			align-items: center;
			input {
				flex: 1;
			}
		}
		button {
			margin: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 160rpx;
			height: 60rpx;
			background: #18aff2;
			color: #fff;
			border-radius: 10rpx;
			font-size: 30rpx;
		}
	}

	// 辅助数量 
	.fz_content {
		width: 1000rpx;
		padding: 80rpx 40rpx;
		background: #fff;
		font-size: 40rpx;
		font-weight: 700;
		position: relative;
		border-radius: 50rpx;
		
		.iconfont {
			position: absolute;
			top: 30rpx;
			right: 50rpx;
			font-size: 40rpx;
		}

		.bottom_btn {
			display: flex;
			justify-content: space-around;
			margin-top: 80rpx;
			
			button {
				width: 400rpx;
				height: 100rpx;
				background: #169bd5;
				color: #fff;
				margin: 0;
				font-weight: 500;
				font-size: 60rpx;
			}
		}
		.toast {
			position: absolute;
			top: 140rpx;
			left: 400rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 20rpx 40rpx;
			border-radius: 15rpx;
			background: #575757;
			color: #fff;
			font-size: 30rpx;
			z-index: inherit;
		}
	}

	// 配货数量弹出框
	.ph_popup_content {
		display: flex;
		flex-direction: column;
		padding: 20rpx;
		border-radius: 20rpx;
		background: #fff;
		font-size: 30rpx;
		min-width: 600rpx;
		max-width: 900rpx;

		.title {
			font-size: 40rpx;
			border-bottom: 1rpx solid #ccc;
		}

		.ph_content_info {
			flex: 1;
			padding: 10rpx 0;
		}

		.ph_footer {
			display: flex;
			align-items: center;
			justify-content: space-between;

			button {
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 0;
				background: #18aff2;
				color: #fff;
			}

			.cpcBtn {
				background: #63a103;
			} 

			.hover_btn {
				background: #ccc;
			}
		}
	}

	// 选中员工 弹出框
	.employee_popup {
		width: 800rpx; 
		height: 600rpx; 
		background: #fff; 
		border-radius: 20rpx; 
		padding: 10rpx; 
		display: flex; 
		flex-direction: column;
		font-size: 40rpx;

		.title {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 50rpx;
			border-bottom: 1rpx solid #ccc;
		} 

		.employee_list {
			flex: 1;
			overflow: auto;

			.label_item {
				display: flex;
				align-items: center;
			}
		}

		.footer {
			display: flex;
			align-items: center;
			justify-content: space-around;
		}

		button {
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0;
			background: #18aff2;
			color: #fff;
		}

		.hover_btn {
			background: #ccc;
		}
	}

}
</style>
